/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package samoloty.controler;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.ArrayList;
import samoloty.data.HoldsPanelArray;
import samoloty.data.HoldsPanelItem;
import samoloty.model.IDataModel;
import samoloty.model.models.HoldsModel;
import samoloty.view.HoldsPanel;
import samoloty.view.InfoSubPanel;
import samoloty.view.MainWindow;
import samoloty.view.MyButton;

/**
 *
 * @author frankowp
 */
public class HoldsPanelControler implements MyControler {

    private HoldsPanel panel;
    private Controler controler;
    private IDataModel dataModel = null;

    public HoldsPanelControler(Controler c) {
        controler = c;
        initPanel();
    }

    public HoldsPanelControler(Controler c, IDataModel data) {
        controler = c;
        dataModel = data;
        initPanel();
    }

    public HoldsPanel getPanel() {
        return panel;
    }

    public void initPanel() {
        panel = new HoldsPanel();
        panel.setB1FocusListener(new ChangeValues());
        panel.setB2FocusListener(new ChangeValues());
        panel.setB3FocusListener(new ChangeValues());
        panel.setB4FocusListener(new ChangeValues());
        panel.setB5FocusListener(new ChangeValues());
        panel.setB5lFocusListener(new ChangeValues());
        panel.setB5rFocusListener(new ChangeValues());
        panel.setB6FocusListener(new ChangeValues());
        panel.setC1FocusListener(new ChangeValues());
        panel.setC2FocusListener(new ChangeValues());
        panel.setC3FocusListener(new ChangeValues());
        panel.setC4FocusListener(new ChangeValues());
        panel.setC5FocusListener(new ChangeValues());
        panel.setC5lFocusListener(new ChangeValues());
        panel.setC5rFocusListener(new ChangeValues());
        panel.setC6FocusListener(new ChangeValues());
        panel.setM1FocusListener(new ChangeValues());
        panel.setM2FocusListener(new ChangeValues());
        panel.setM3FocusListener(new ChangeValues());
        panel.setM4FocusListener(new ChangeValues());
        panel.setM5FocusListener(new ChangeValues());
        panel.setM5lFocusListener(new ChangeValues());
        panel.setM5rFocusListener(new ChangeValues());
        panel.setM6FocusListener(new ChangeValues());

        initData();

    }

    public void initData() {
        panel.unhide();
        //TODO na pewnoe będą nowe bazy, więc trzeba maxy zrobić
        if (dataModel != null) {
            try {
                ArrayList<HoldsModel> holds = dataModel.getHolds();
                int i1 = getHoldIndex("1");
                int i2 = getHoldIndex("2");
                int i3 = getHoldIndex("3");
                int i4 = getHoldIndex("4");
                int i5 = getHoldIndex("5");
                int i5l = getHoldIndex("5L");
                int i5r = getHoldIndex("5R");
                int i6 = getHoldIndex("6");
                if (i1 == -1) {
                    panel.hideField("1");
                } else {
                    panel.setMax1Lab(Integer.toString(holds.get(i1).getWeight()));
                }
                if (i2 == -1) {
                    panel.hideField("2");
                } else {
                    panel.setMax2Lab(Integer.toString(holds.get(i2).getWeight()));
                }
                if (i3 == -1) {
                    panel.hideField("3");
                } else {
                    panel.setMax3Lab(Integer.toString(holds.get(i3).getWeight()));
                }
                if (i4 == -1) {
                    panel.hideField("4");
                } else {
                    panel.setMax4Lab(Integer.toString(holds.get(i4).getWeight()));
                }
                if (i5 == -1) {
                    panel.hideField("5");
                } else {
                    panel.setMax5Lab(Integer.toString(holds.get(i5).getWeight()));
                }
                if (i5l == -1) {
                    panel.hideField("5l");
                } else {
                    panel.setMax5lLab(Integer.toString(holds.get(i5l).getWeight()));
                }
                if (i5r == -1) {
                    panel.hideField("5r");
                } else {
                    panel.setMax5rLab(Integer.toString(holds.get(i5r).getWeight()));
                }
                if (i6 == -1) {
                    panel.hideField("6");
                } else {
                    panel.setMax6Lab(Integer.toString(holds.get(i6).getWeight()));
                }

                panel.center();

            } catch (Exception e) {
                System.out.println("nie ma holdsow");
            }
        }
    }

    public void setUpWindow() {
        MainWindow window = controler.getView();
        panel.setPlotPanel(controler.getPlotPanel());

        InfoPanelControler infoPanelControler = controler.getInfoPanelControler();
        InfoSubPanel infoSubPanel = infoPanelControler.getPanel();
        panel.addInfoSubPanel(infoSubPanel);

        window.setLeftPanelVisible(true);
        window.setRightPanelVisible(true);
        window.setAllBtnStyle(MyButton.ACTIVE_BUTTON);
        window.setHoldsBtnStyle(MyButton.CHOOSE_BUTTON);
        firstFocused();
        controler.getPlotPanelControler().update();
    }

    public void reset() {
        panel.reset();
    }

    public void setDataModel(IDataModel dataModel) {
        this.dataModel = dataModel;
        initData();
    }

    void set_vttlholdsw(double vttlholdsw) {
        panel.set_vttlholdsw(vttlholdsw);
    }

    public void firstFocused() {
        panel.setFirstFieldActive();
    }

    private class ChangeValues implements FocusListener {

        public void focusGained(FocusEvent fe) {
            controler.getMainValidator().validate();
        }

        public void focusLost(FocusEvent fe) {
            int vttlhold1 = get_vttlhold1();
            int vttlhold2 = get_vttlhold2();
            int vttlhold3 = get_vttlhold3();
            int vttlhold4 = get_vttlhold4();
            int vttlhold5 = get_vttlhold5();
            int vttlhold5l = get_vttlhold5l();
            int vttlhold5r = get_vttlhold5r();
            int vttlhold6 = get_vttlhold6();

            int vttlholdb = get_vttlholdb();
            int vttlholdc = get_vttlholdc();
            int vttlholdm = get_vttlholdm();

            panel.setTtl1Lab(Integer.toString(vttlhold1));
            panel.setTtl2Lab(Integer.toString(vttlhold2));
            panel.setTtl3Lab(Integer.toString(vttlhold3));
            panel.setTtl4Lab(Integer.toString(vttlhold4));
            panel.setTtl5Lab(Integer.toString(vttlhold5));
            panel.setTtl5lLab(Integer.toString(vttlhold5l));
            panel.setTtl5rLab(Integer.toString(vttlhold5r));
            panel.setTtl6Lab(Integer.toString(vttlhold6));

            panel.setTTLBLab(Integer.toString(vttlholdb));
            panel.setTTLCLab(Integer.toString(vttlholdc));
            panel.setTTLMLab(Integer.toString(vttlholdm));
            controler.getInfoPanelControler().update();
            //panel.setPlotPanel(controler.getPlotPanel());

            if (vttlhold1 < Integer.parseInt(panel.getmax1Lab())) {
                panel.hideMaximumLoadExceed();
            }
            if (vttlhold2 < Integer.parseInt(panel.getmax2Lab())) {
                panel.hideMaximumLoadExceed();
            }
            if (vttlhold3 < Integer.parseInt(panel.getmax3Lab())) {
                panel.hideMaximumLoadExceed();
            }
            if (vttlhold4 < Integer.parseInt(panel.getmax4Lab())) {
                panel.hideMaximumLoadExceed();
            }
            if (vttlhold5 < Integer.parseInt(panel.getmax5Lab())) {
                panel.hideMaximumLoadExceed();
            }
            if (vttlhold5l < Integer.parseInt(panel.getmax5lLab())) {
                panel.hideMaximumLoadExceed();
            }
            if (vttlhold5r < Integer.parseInt(panel.getmax5rLab())) {
                panel.hideMaximumLoadExceed();
            }
            if (vttlhold6 < Integer.parseInt(panel.getmax6Lab())) {
                panel.hideMaximumLoadExceed();
            }
            if (vttlhold1 > Integer.parseInt(panel.getmax1Lab())) {
                panel.showMaximumLoadExceed();
            }
            if (vttlhold2 > Integer.parseInt(panel.getmax2Lab())) {
                panel.showMaximumLoadExceed();
            }
            if (vttlhold3 > Integer.parseInt(panel.getmax3Lab())) {
                panel.showMaximumLoadExceed();
            }
            if (vttlhold4 > Integer.parseInt(panel.getmax4Lab())) {
                panel.showMaximumLoadExceed();
            }
            if (vttlhold5 > Integer.parseInt(panel.getmax5Lab())) {
                panel.showMaximumLoadExceed();
            }
            if (vttlhold5l > Integer.parseInt(panel.getmax5lLab())) {
                panel.showMaximumLoadExceed();
            }
            if (vttlhold5r > Integer.parseInt(panel.getmax5rLab())) {
                panel.showMaximumLoadExceed();
            }
            if (vttlhold6 > Integer.parseInt(panel.getmax6Lab())) {
                panel.showMaximumLoadExceed();
            }
            controler.getPlotPanel().update();
        }
    }

    public HoldsPanelItem getHoldsPanelItemNo1() {
        HoldsPanelItem result = new HoldsPanelItem();
        int baggage = 0;
        int cargo = 0;
        int mail = 0;
        int total = 0;
        try {
            baggage = Integer.parseInt(panel.get_vhold1b());
            cargo = Integer.parseInt(panel.get_vhold1c());
            mail = Integer.parseInt(panel.get_vhold1m());
            total = Integer.parseInt(panel.get_vttlhold1());
        } catch (NumberFormatException e) {
            System.err.println("Holds Panel. Bledny format danych.");
        }
        result.setIndex(1);
        result.setBaggage(baggage);
        result.setCargo(cargo);
        result.setMail(mail);
        result.setTotal(total);
        return result;
    }

    public HoldsPanelItem getHoldsPanelItemNo2() {
        HoldsPanelItem result = new HoldsPanelItem();
        int baggage = 0;
        int cargo = 0;
        int mail = 0;
        int total = 0;
        try {
            baggage = Integer.parseInt(panel.get_vhold2b());
            cargo = Integer.parseInt(panel.get_vhold2c());
            mail = Integer.parseInt(panel.get_vhold2m());
            total = Integer.parseInt(panel.get_vttlhold2());
        } catch (NumberFormatException e) {
            System.err.println("Holds Panel. Bledny format danych.");
        }
        result.setIndex(2);
        result.setBaggage(baggage);
        result.setCargo(cargo);
        result.setMail(mail);
        result.setTotal(total);
        return result;
    }

    public HoldsPanelItem getHoldsPanelItemNo3() {
        HoldsPanelItem result = new HoldsPanelItem();
        int baggage = 0;
        int cargo = 0;
        int mail = 0;
        int total = 0;
        try {
            baggage = Integer.parseInt(panel.get_vhold3b());
            cargo = Integer.parseInt(panel.get_vhold3c());
            mail = Integer.parseInt(panel.get_vhold3m());
            total = Integer.parseInt(panel.get_vttlhold3());
        } catch (NumberFormatException e) {
            System.err.println("Holds Panel. Bledny format danych.");
        }
        result.setIndex(3);
        result.setBaggage(baggage);
        result.setCargo(cargo);
        result.setMail(mail);
        result.setTotal(total);
        return result;
    }

    public HoldsPanelItem getHoldsPanelItemNo4() {
        HoldsPanelItem result = new HoldsPanelItem();
        int baggage = 0;
        int cargo = 0;
        int mail = 0;
        int total = 0;
        try {
            baggage = Integer.parseInt(panel.get_vhold4b());
            cargo = Integer.parseInt(panel.get_vhold4c());
            mail = Integer.parseInt(panel.get_vhold4m());
            total = Integer.parseInt(panel.get_vttlhold4());
        } catch (NumberFormatException e) {
            System.err.println("Holds Panel. Bledny format danych.");
        }
        result.setIndex(4);
        result.setBaggage(baggage);
        result.setCargo(cargo);
        result.setMail(mail);
        result.setTotal(total);
        return result;
    }

    public HoldsPanelItem getHoldsPanelItemNo5() {
        HoldsPanelItem result = new HoldsPanelItem();
        int baggage = 0;
        int cargo = 0;
        int mail = 0;
        int total = 0;
        try {
            baggage = Integer.parseInt(panel.get_vhold5b());
            cargo = Integer.parseInt(panel.get_vhold5c());
            mail = Integer.parseInt(panel.get_vhold5m());
            total = Integer.parseInt(panel.get_vttlhold5());
        } catch (NumberFormatException e) {
            System.err.println("Holds Panel. Bledny format danych.");
        }
        result.setIndex(5);
        result.setBaggage(baggage);
        result.setCargo(cargo);
        result.setMail(mail);
        result.setTotal(total);
        return result;
    }

    public HoldsPanelItem getHoldsPanelItemNo5l() {
        HoldsPanelItem result = new HoldsPanelItem();
        int baggage = 0;
        int cargo = 0;
        int mail = 0;
        int total = 0;
        try {
            baggage = Integer.parseInt(panel.get_vhold5lb());
            cargo = Integer.parseInt(panel.get_vhold5lc());
            mail = Integer.parseInt(panel.get_vhold5lm());
            total = Integer.parseInt(panel.get_vttlhold5l());
        } catch (NumberFormatException e) {
            System.err.println("Holds Panel. Bledny format danych.");
        }
        result.setIndex(6);
        result.setBaggage(baggage);
        result.setCargo(cargo);
        result.setMail(mail);
        result.setTotal(total);
        return result;
    }

    public HoldsPanelItem getHoldsPanelItemNo5r() {
        HoldsPanelItem result = new HoldsPanelItem();
        int baggage = 0;
        int cargo = 0;
        int mail = 0;
        int total = 0;
        try {
            baggage = Integer.parseInt(panel.get_vhold5rb());
            cargo = Integer.parseInt(panel.get_vhold5rc());
            mail = Integer.parseInt(panel.get_vhold5rm());
            total = Integer.parseInt(panel.get_vttlhold5r());
        } catch (NumberFormatException e) {
            System.err.println("Holds Panel. Bledny format danych.");
        }
        result.setIndex(6);
        result.setBaggage(baggage);
        result.setCargo(cargo);
        result.setMail(mail);
        result.setTotal(total);
        return result;
    }

    public HoldsPanelItem getHoldsPanelItemNo6() {
        HoldsPanelItem result = new HoldsPanelItem();
        int baggage = 0;
        int cargo = 0;
        int mail = 0;
        int total = 0;
        try {
            baggage = Integer.parseInt(panel.get_vhold6b());
            cargo = Integer.parseInt(panel.get_vhold6c());
            mail = Integer.parseInt(panel.get_vhold6m());
            total = Integer.parseInt(panel.get_vttlhold6());
        } catch (NumberFormatException e) {
            System.err.println("Holds Panel. Bledny format danych.");
        }
        result.setIndex(7);
        result.setBaggage(baggage);
        result.setCargo(cargo);
        result.setMail(mail);
        result.setTotal(total);
        return result;
    }

    public HoldsPanelArray getHoldsPanelArray() {
        HoldsPanelArray result = new HoldsPanelArray();
        int count = dataModel.getHolds().size();//ilosc holdsow
        if (count > 0) {
            result.add(getHoldsPanelItemNo1());
        }
        if (count > 1) {
            result.add(getHoldsPanelItemNo2());
        }
        if (count > 2) {
            result.add(getHoldsPanelItemNo3());
        }
        if (count > 3) {
            result.add(getHoldsPanelItemNo4());
        }
        if (count > 4) {
            result.add(getHoldsPanelItemNo5());
        }
        if (count > 5) {
            result.add(getHoldsPanelItemNo5l());
        }
        if (count > 6) {
            result.add(getHoldsPanelItemNo5r());
        }
        if (count > 6) {
            result.add(getHoldsPanelItemNo6());
        }
        return result;
    }

    public double getDataHoldsIndex(String hold) {
        double result = 0;
        ArrayList<HoldsModel> holds = dataModel.getHolds();
        for (int i = 0; i < holds.size(); i++) {
            HoldsModel holdData = holds.get(i);
            if (holdData.getHold().equals(hold)) {
                return holdData.getIndex();
            }
        }
        return result;
    }

    public int getDataHoldsWeight(String hold) {
        ArrayList<HoldsModel> holds = dataModel.getHolds();
        for (int i = 0; i < holds.size(); i++) {
            HoldsModel holdData = holds.get(i);
            if (holdData.getHold().equals(hold)) {
                return holdData.getWeight();
            }
        }
        return -1;
    }

    public int getHoldIndex(String hold) {
        ArrayList<HoldsModel> holds = controler.getDataModel().getHolds();
        for (int i = 0; i < holds.size(); i++) {
            HoldsModel holdData = holds.get(i);
            if (holdData.getHold().equals(hold)) {
                return i;
            }
        }
        return -1;
    }

    public int get_vttlhold1() {
        int vhold1b = 0;
        int vhold1c = 0;
        int vhold1m = 0;
        if (panel.getb1Text().equals("") == false) {
            vhold1b = Integer.parseInt(panel.getb1Text());
        }
        if (panel.getc1Text().equals("") == false) {
            vhold1c = Integer.parseInt(panel.getc1Text());
        }

        if (panel.getm1Text().equals("") == false) {
            vhold1m = Integer.parseInt(panel.getm1Text());
        }
        int vttlhold1 = vhold1b + vhold1c + vhold1m;
        return vttlhold1;
    }

    public int get_vttlhold2() {
        int vhold2b = 0;
        int vhold2c = 0;
        int vhold2m = 0;
        if (panel.getb2Text().equals("") == false) {
            vhold2b = Integer.parseInt(panel.getb2Text());
        }
        if (panel.getc2Text().equals("") == false) {
            vhold2c = Integer.parseInt(panel.getc2Text());
        }

        if (panel.getm2Text().equals("") == false) {
            vhold2m = Integer.parseInt(panel.getm2Text());
        }
        int vttlhold2 = vhold2b + vhold2c + vhold2m;
        return vttlhold2;
    }

    public int get_vttlhold3() {
        int vhold3b = 0;
        int vhold3c = 0;
        int vhold3m = 0;
        if (panel.getb3Text().equals("") == false) {
            vhold3b = Integer.parseInt(panel.getb3Text());
        }
        if (panel.getc3Text().equals("") == false) {
            vhold3c = Integer.parseInt(panel.getc3Text());
        }

        if (panel.getm1Text().equals("") == false) {
            vhold3m = Integer.parseInt(panel.getm3Text());
        }
        int vttlhold3 = vhold3b + vhold3c + vhold3m;
        return vttlhold3;
    }

    public int get_vttlhold4() {
        int vhold4b = 0;
        int vhold4c = 0;
        int vhold4m = 0;
        if (panel.getb4Text().equals("") == false) {
            vhold4b = Integer.parseInt(panel.getb4Text());
        }
        if (panel.getc4Text().equals("") == false) {
            vhold4c = Integer.parseInt(panel.getc4Text());
        }

        if (panel.getm4Text().equals("") == false) {
            vhold4m = Integer.parseInt(panel.getm4Text());
        }
        int vttlhold4 = vhold4b + vhold4c + vhold4m;
        return vttlhold4;
    }

    public int get_vttlhold5l() {
        int vhold5lb = 0;
        int vhold5lc = 0;
        int vhold5lm = 0;
        if (panel.getb5lText().equals("") == false) {
            vhold5lb = Integer.parseInt(panel.getb5lText());
        }
        if (panel.getc5lText().equals("") == false) {
            vhold5lc = Integer.parseInt(panel.getc5lText());
        }

        if (panel.getm5lText().equals("") == false) {
            vhold5lm = Integer.parseInt(panel.getm5lText());
        }
        int vttlhold5l = vhold5lb + vhold5lc + vhold5lm;
        return vttlhold5l;
    }

    public int get_vttlhold5() {
        int vhold5b = 0;
        int vhold5c = 0;
        int vhold5m = 0;
        if (panel.getb5Text().equals("") == false) {
            vhold5b = Integer.parseInt(panel.getb5Text());
        }
        if (panel.getc5Text().equals("") == false) {
            vhold5c = Integer.parseInt(panel.getc5Text());
        }

        if (panel.getm5Text().equals("") == false) {
            vhold5m = Integer.parseInt(panel.getm5Text());
        }
        int vttlhold5 = vhold5b + vhold5c + vhold5m;
        return vttlhold5;
    }

    public int get_vttlhold5r() {
        int vhold5rb = 0;
        int vhold5rc = 0;
        int vhold5rm = 0;
        if (panel.getb5rText().equals("") == false) {
            vhold5rb = Integer.parseInt(panel.getb5rText());
        }
        if (panel.getc5rText().equals("") == false) {
            vhold5rc = Integer.parseInt(panel.getc5rText());
        }

        if (panel.getm5lText().equals("") == false) {
            vhold5rm = Integer.parseInt(panel.getm5rText());
        }
        int vttlhold5r = vhold5rb + vhold5rc + vhold5rm;
        return vttlhold5r;
    }

    public int get_vttlhold6() {
        int vhold6b = 0;
        int vhold6c = 0;
        int vhold6m = 0;
        if (panel.getb6Text().equals("") == false) {
            vhold6b = Integer.parseInt(panel.getb6Text());
        }
        if (panel.getc6Text().equals("") == false) {
            vhold6c = Integer.parseInt(panel.getc6Text());
        }

        if (panel.getm6Text().equals("") == false) {
            vhold6m = Integer.parseInt(panel.getm6Text());
        }
        int vttlhold6 = vhold6b + vhold6c + vhold6m;
        return vttlhold6;
    }

    public int get_vttlholdb() {
        int vhold1b = 0;
        int vhold2b = 0;
        int vhold3b = 0;
        int vhold4b = 0;
        int vhold5b = 0;
        int vhold5lb = 0;
        int vhold5rb = 0;
        int vhold6b = 0;

        if (panel.getb1Text().equals("") == false) {
            vhold1b = Integer.parseInt(panel.getb1Text());
        }
        if (panel.getb2Text().equals("") == false) {
            vhold2b = Integer.parseInt(panel.getb2Text());
        }
        if (panel.getb3Text().equals("") == false) {
            vhold3b = Integer.parseInt(panel.getb3Text());
        }
        if (panel.getb4Text().equals("") == false) {
            vhold4b = Integer.parseInt(panel.getb4Text());
        }
        if (panel.getb5Text().equals("") == false) {
            vhold5b = Integer.parseInt(panel.getb5Text());
        }
        if (panel.getb5lText().equals("") == false) {
            vhold5lb = Integer.parseInt(panel.getb5lText());
        }
        if (panel.getb5rText().equals("") == false) {
            vhold5rb = Integer.parseInt(panel.getb5rText());
        }
        if (panel.getb6Text().equals("") == false) {
            vhold6b = Integer.parseInt(panel.getb6Text());
        }
        int vttlholdb = vhold1b + vhold2b + vhold3b + vhold4b + vhold5b + vhold5lb + vhold5rb + vhold6b;
        return vttlholdb;
    }

    public int get_vttlholdc() {
        int vhold1c = 0;
        int vhold2c = 0;
        int vhold3c = 0;
        int vhold4c = 0;
        int vhold5c = 0;
        int vhold5lc = 0;
        int vhold5rc = 0;
        int vhold6c = 0;

        if (panel.getc1Text().equals("") == false) {
            vhold1c = Integer.parseInt(panel.getc1Text());
        }
        if (panel.getc2Text().equals("") == false) {
            vhold2c = Integer.parseInt(panel.getc2Text());
        }
        if (panel.getc3Text().equals("") == false) {
            vhold3c = Integer.parseInt(panel.getc3Text());
        }
        if (panel.getc4Text().equals("") == false) {
            vhold4c = Integer.parseInt(panel.getc4Text());
        }
        if (panel.getc5Text().equals("") == false) {
            vhold5c = Integer.parseInt(panel.getc5Text());
        }
        if (panel.getc5lText().equals("") == false) {
            vhold5lc = Integer.parseInt(panel.getc5lText());
        }
        if (panel.getc5rText().equals("") == false) {
            vhold5rc = Integer.parseInt(panel.getc5rText());
        }
        if (panel.getc6Text().equals("") == false) {
            vhold6c = Integer.parseInt(panel.getc6Text());
        }

        int vttlholdc = vhold1c + vhold2c + vhold3c + vhold4c + vhold5c + vhold5lc + vhold5rc + vhold6c;
        return vttlholdc;
    }

    public int get_vttlholdm() {
        int vhold1m = 0;
        int vhold2m = 0;
        int vhold3m = 0;
        int vhold4m = 0;
        int vhold5m = 0;
        int vhold5lm = 0;
        int vhold5rm = 0;
        int vhold6m = 0;

        if (panel.getm1Text().equals("") == false) {
            vhold1m = Integer.parseInt(panel.getm1Text());
        }
        if (panel.getm2Text().equals("") == false) {
            vhold2m = Integer.parseInt(panel.getm2Text());
        }
        if (panel.getm3Text().equals("") == false) {
            vhold3m = Integer.parseInt(panel.getm3Text());
        }
        if (panel.getm4Text().equals("") == false) {
            vhold4m = Integer.parseInt(panel.getm4Text());
        }
        if (panel.getm5Text().equals("") == false) {
            vhold5m = Integer.parseInt(panel.getm5Text());
        }
        if (panel.getm5lText().equals("") == false) {
            vhold5lm = Integer.parseInt(panel.getm5lText());
        }
        if (panel.getm5rText().equals("") == false) {
            vhold5rm = Integer.parseInt(panel.getm5rText());
        }
        if (panel.getm6Text().equals("") == false) {
            vhold6m = Integer.parseInt(panel.getm6Text());
        }

        int vttlholdm = vhold1m + vhold2m + vhold3m + vhold4m + vhold5m + vhold5lm + vhold5rm + vhold6m;
        return vttlholdm;
    }

    public boolean isValid() {
        return panel.isValid();
    }
}
